package com.demo.word;

import com.deepoove.poi.XWPFTemplate;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;

/**
 * @author gy
 * @date 2024/1/4
 */
public class DemoTest {
    @Test
    public void m1() throws IOException {
        long startTime = System.currentTimeMillis();

        String filePath = "D:\\demo_project\\20240102-excel-study\\src\\main\\resources\\template.docx";
        XWPFTemplate template = XWPFTemplate.compile(filePath).render(
                new HashMap<String, Object>(){{
                    put("title", "Hi, poi-tl Word模板引擎");
                    put("name", "张三");
                    put("age", 11);
                }});
        template.writeAndClose(new FileOutputStream("output.docx"));

        long endTime = System.currentTimeMillis();
        System.out.println("执行耗时["+(endTime - startTime)+"]毫秒");
    }
}
